package cn.gok.demo21.controller;

import cn.gok.demo21.entity.Student;
import cn.gok.demo21.service.StudentService;
import cn.gok.demo21.service.impl.ClazzServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.transform.Result;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/student")
public class StudentController   {
    @Autowired
    private StudentService studentService ;


    //1 查询所有学生信息*
    @RequestMapping("/findAll")
    public List<Student> findAllStudent(){
        return studentService.list(null);
    }
    //2 根据ID查询学生信息*
    @RequestMapping("/findByid")
    public Student findStudentByid(@RequestParam Long id){
        return studentService.getById(id);
    }
    //3 模糊查询学生信息*
    @RequestMapping("/findBywrapper")
    private List<Student> fuzzyQuery(@RequestBody Student student){
        QueryWrapper<Student> wrapper = new QueryWrapper<>();
       wrapper.like("sid",student.getSid()).or()
                .like("sname",student.getSname()).or()
                .like("sex",student.getSex()).or()
                .like("snum",student.getSnum());
        List<Student> list =studentService.list(wrapper);
        return list;
    }

    //4 分页查询学生信息*

    @RequestMapping("/page")
    public IPage<Student> findPage(){
        Page<Student> page=new Page<>(1,3);
        return studentService.page(page,null);
    }
    //5 添加学生信息*
    @RequestMapping("/save")
    public boolean saveStudent(@RequestBody Student student){
        return studentService.save(student);
    }
    //6 修改学生信息*
    @RequestMapping("/update")
    public boolean updateStudent(@RequestBody Student student){
        return studentService.updateById(student);
    }
    //7 根据ID删除学生*
    @RequestMapping("/removeById")
    public boolean removeStudentByid(@RequestParam Long id){
        return studentService.removeById(id);
    }
    //8 批量删除学生*
    @RequestMapping("/removeByIds")
    public boolean removeStudentByIds(@RequestParam List<Integer> ids){
        return studentService.removeByIds(ids);
    }
}
